﻿using ERPEF.Model;
using ERPIService;
using Microsoft.EntityFrameworkCore;
using S4Project;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ERPService
{
    public class pur_Chase_ReceiptService : pur_Chase_ReceiptIService
    {
        private readonly MyDbContext MyDbContext;
        public pur_Chase_ReceiptService(MyDbContext myDb)
        {
            this.MyDbContext = myDb;
        }

        //主添加
        public async Task<int> ReceiptAdd(pur_Chase_Receipt Chase_Receipt)
        {
            await MyDbContext.pur_Chase_Receipt.AddAsync(Chase_Receipt);
            return await MyDbContext.SaveChangesAsync();
        }

        //主删除
        public async Task<int> ReceiptDelete(int pr_id)
        {
            var del = MyDbContext.pur_Chase_Receipt.Find(pr_id);
            if (del != null)
            {
                del.IsDeleted = true;
                await MyDbContext.SaveChangesAsync();
                return 1;
            }
            return 0;
        }

        //主修改
        public async Task<int> ReceiptUpdate(pur_Chase_Receipt Chase_Receipt)
        {
            MyDbContext.pur_Chase_Receipt.Update(Chase_Receipt);
            return await MyDbContext.SaveChangesAsync(); 
        }





        //从添加
        public async Task<int> FromAdd(pur_Chase_From Chase_From)
        {
            await MyDbContext.pur_Chase_From.AddAsync(Chase_From);
            return await MyDbContext.SaveChangesAsync();
        }

        //从删除
        public async Task<int> FromDelete(int pf_id)
        {
            var del = MyDbContext.pur_Chase_From.Find(pf_id);
            if (del != null)
            {
                del.IsDeleted = true;
                await MyDbContext.SaveChangesAsync();
                return 1;
            }
            return 0;
        }

        //从修改
        public async Task<int> FromUpdate(pur_Chase_From Chase_From)
        {
            MyDbContext.pur_Chase_From.Update(Chase_From);
            return await MyDbContext.SaveChangesAsync();
        }
    }
}
